#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node
{
char userid[50];
char pwd[50];
}

main()
{
FILE *fp;
int i,j,d=0,h,cmp=100,cmp2=100,x=0,k,t=0;
char id[50];
struct node *hash;
struct node *array[1000];
char uid[30];
char pswd[30];
fp=fopen("names","r");
for(i=0;i<150;i++)
{
d=0;
hash=malloc(sizeof(struct node));
fscanf(fp,"%s %s",hash->userid,hash->pwd);
strcpy(id,hash->userid);
for(k=0;id[k]!='\0';k++);

for (j=0;j<k;j++)
d=d-j+id[j];

h=(d+k)%150;

while(array[h]!='\0')
h=h+1;
//printf("%d \n",h);
array[h]=hash;
}

while (t<3)
{
x=0;
printf("Enter a username:");
scanf("%s",uid);
printf("Enter a password:");
scanf("%s",pswd);

for(k=0;uid[k]!='\0';k++);

for(j=0;j<k;j++)
x=x-j+uid[j];

h=(x+k)%150;

int result = strncmp(array[h]->userid, uid, cmp);
int result2 = strncmp(pswd, array[h]->pwd, cmp2);

while(h<150)
{
if(result==0)

{
if(result2==0)
{printf("Password matched. \n");
break;
t=4;
}
else{
printf("Incorrect password. \n");
break;}
}
else
h=h+1;
}
if(h==150)
printf("No such user id exists.\n");
t=t+1;
}
if (t==3)
printf("Too many tries!!!\n");
}

